#ifndef GameObject_h__
#define GameObject_h__

#include "EventSet.h"
#include "PropertySet.h"

#include "../Common/Common.h"
#include "PropertyIDs.h"

enum ObjectType
{
	OT_INVAIL,
	OT_PLAYER
};

enum ObjectTypeId
{
	ITID_INVALID,
	ITID_PLAYER
};

class GameObject : public EventSet, public PropertySet
{
protected:
	GameObject::GameObject(void) :m_guid(0),m_type(0),m_typeid(0)
	{
	}


	bool GameObject::create(uint64 guid, const std::string& name)
	{
		m_name = name;
		m_guid = guid;
		setValue(PID_GUID_LOW, (uint32)guid & 0xFFFFFFFF);
		setValue(PID_GUID_HIGH, (uint32)(guid >> 32));
		setValue(PID_NAME,name.c_str());
		return true;
	}


public:
	std::string getName() const
	{
		return m_name;
	}

	uint64 getGUID() const
	{
		return m_guid;
	}

private:
	uint64 m_guid;
	std::string m_name;

	uint8 m_type;
	uint8 m_typeid;
};


class WorldObject : public GameObject
{
protected:
	WorldObject() : m_is_inworld(false) {}

public:
	
	bool create(uint64 guid, const std::string& name, uint32 mapid, float x, float y, float z)
	{
		GameObject::create(guid,name);
		setMapID(mapid);
		setPosition(x,y,z);

		return true;
	}

	void setPosition(float x, float y, float z)
	{
		setValue(PID_POS_X,x);
		setValue(PID_POS_Y,y);
		setValue(PID_POS_Z,z);
	}

	void getPosition(float& x, float& y, float& z) const
	{
		getValue(PID_POS_X,x);
		getValue(PID_POS_Y,y);
		getValue(PID_POS_Z,z);
	}

	void setX(float x)
	{
		setValue(PID_POS_X,x);
	}

	void setY(float y)
	{
		setValue(PID_POS_Y,y);
	}

	void setZ(float z)
	{
		setValue(PID_POS_Z,z);
	}

	float setO(float o)
	{
		setValue(PID_POS_O,o);
	}

	float getX() const
	{
		float x;
		getValue(PID_POS_X,x);
		return x;
	}

	float getY() const
	{
		float y;
		getValue(PID_POS_Y,y);
		return y;
	}

	float getZ() const
	{
		float z;
		getValue(PID_POS_Z,z);
		return z;
	}

	float getO() const
	{
		float o;
		getValue(PID_POS_O,o);
		return o;
	}

	void setInWorld(bool bl)
	{
		m_is_inworld = bl;
		onInworld();
	}

	void removeFromWorld()
	{
		m_is_inworld = false;
		onRemoveFromWorld();
	}

	bool isInWorld() const
	{
		return m_is_inworld;
	}

	void setMapID(uint32 id)
	{
		getValue(PID_MAP_ID,id);
	}

	uint32 getMapID() const
	{
		uint32 id;
		getValue(PID_MAP_ID,id);
		return id;
	}

protected:
	virtual void onInworld()
	{

	}

	virtual void onRemoveFromWorld()
	{

	}

private:
	bool m_is_inworld;
};


#endif // GameObject_h__

